<template>
  <div class="AdminBlog"><BlogTable :table-head="head" Delete="BlogDelete" :content="content" :table-update="update" :total="count" @page="page" ref="child" :select="select" @pagin="pagin">
      <div>
        <select >
      <option value="name">标题</option>
         </select>
      </div>
      <div>
        <input type="text" placeholder="请输入查询信息" v-model="select">
      </div>
      <div class="selectIcon" @click="pagin()">
        <img src="../../public/img/搜索3.png">
      </div>
    </BlogTable>
  </div>
</template>

<script>
import BlogTable from "@/components/BlogTable";
export default {
name: "AdminBlog",
  components:{
    BlogTable
  },
  data(){
    return {
         head:['编号','标题','内容','用户名','所在目录'],
         content:[],
         update:1,
         count:0,
        select:''
    }
  },
  methods:{
     pagin(current = 1){
       this.content = [];
       const request = this.myCode();
       const config = {
         method:'get',
         url:'/BlogQueryPagin',
         params:{
               'select':this.select,
              'current':current
         }
       }
       request(config).then((res)=>{
         var arr =    res.data.result;
         this.count = res.data.total;
          this.Arrpush(arr);
       })
     },
      Arrpush(arr){
        for(var i=0;i<arr.length;i++){
          var list = {};
          list['id'] = arr[i].id;
          list['title'] = arr[i].title;
          var Acontent = arr[i].content.substring(0,40);
          Acontent = Acontent+'......'
          list['content'] = Acontent;
          list['user']=arr[i]['get_user']['name'];
          list['directory']=arr[i]['get_directory']['name'];
          this.content.push(list);
        }
      },
      page(current = 0){
        this.content = [];
        const request = this.myCode();
        var params = {}
        if(current != 0){
           params = {'currentNum':current}
        }
        console.log(params);
        const config = {
          method:'get',
          url:'/GetBlogContent',
          params
        }
        request(config).then((res)=>{
          var arr =    res.data.data;
          this.count = res.data.total;
           this.Arrpush(arr);
        })
      }
  },
  created() {
     this.page();
  }
}
</script>

